var util = {
	remoteInvoke: function(url, data, callback) {
		$.ajax({
			url: url,
			data: data,
			async: true,
			type: "POST",
			dataType: "json",
			success: callback
		});
	},
	isEquals: function(str1, str2) {
		return str1.localeCompare(str2) == 0;
	},
	isEmpty: function(str) {
		str = str.replace(/(^\s*)|(\s*$)/g, ""); 
		return str.length == 0;
	},
	isEmail: function(strEmail) {
		var pattern=/^([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/gi;
		if(!pattern.test(strEmail)) {
			return false;
		} else {
			return true;
		}
	},
	isPhoneNum: function(strNum) {
		//手机
	    var pattern = /(^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$)|(^0{0,1}1[3|4|5|6|7|8|9][0-9]{9}$)/;
        if(pattern.test(strNum)) { 
            return true; 
        }else{ 
        	//固话
        	var result= strNum.match(/\d{3}-\d{8}|\d{4}-\d{7}/);
			if(result !=null) {
				return true;
			} else {
				return false;
			}
        }
	},
	isMobile:function(str){
		var pattern = /^1[3|4|5|6|7|8|9][0-9]{9}$/;
		if(pattern.test(str)) { 
            return true; 
        }else{
        	return false;
        } 
	},
	isBspUsernameFormat : function(str){
		var pattern = /^[^\s]{3,8}$/;
		if(pattern.test(str)){
			return true;
		} else {
			return false;
		}
	},
	isBspUseraliasFormat : function(str){
		var pattern = /^[^\s]{1,20}$/;
		if(pattern.test(str)){
			return true;
		} else {
			return false;
		}
	},
	isBspPasswordFormat : function(str){
		var pattern = /^[^\s]{6,20}$/;
		if(pattern.test(str)){
			return true;
		} else {
			return false;
		}
	},
	clearHint: function($this) {
		$this.parent().next().text("");
	},
	accessAddrText: function(url, data, callback) {
		$.ajax({
			url: url,
			data: data,
			async: true,
			type: "POST",
			success: function(msg){
				var datas = $.parseJSON(msg);
				if(datas.code==1){
					callback(msg);
				}else if(datas.code== -100){
					common.createAlertDialog("提示", "您还没有登录，请点击确定转跳至登录页面", true, function () {
						var loginUrl = "/bsp/web/account/user/login";
						window.top.location.href = loginUrl;
						return true;
					});
				}else{
					common.createAlertDialog("操作失败", datas.info, true);
				}
				
			}
		});
	},
	accessAddrTextSync: function(url, data, callback,mask) {
		$.ajax({
			url: url,
			data: data,
			async: false,
			type: "POST",
			beforeSend:function(){
                if(!mask)
                    return;

                var layer = $("[name='_请求遮罩层']");
                if(layer.length==0){
                    layer = $('<div name="_请求遮罩层" class="post-layer-panel"></div>');
                    layer.appendTo("body");
                }
                layer.show();
            },
            complete:function(){
                if(!mask)
                    return;

                var layer = $("[name='_请求遮罩层']");
                layer.hide();
            },
			success: function(msg){
				var datas = $.parseJSON(msg);
				if(datas.code==1){
					callback(msg);
				}else if(datas.code== -100){
					common.createAlertDialog("提示", "您还没有登录，请点击确定转跳至登录页面", true, function () {
						var loginUrl = "/bsp/web/account/user/login";
						window.top.location.href = loginUrl;
						return true;
					});
				}else{
					common.createAlertDialog("操作失败", datas.info, true);
				}
			}
		});
	},
	jumpToNewPage : function(seconds, urlOfNewPage, htmlTagId){
		var p = count = 1;
		while(p <= seconds){
			window.setTimeout(function(a){
				var displayNumber = p-(count++);
				$('#'+htmlTagId).text(displayNumber+'');
				if(displayNumber == 1){
					window.setTimeout(function(a){
						location.href = urlOfNewPage;
					}, 1000);
				}
			},p++*1000);
		}
	},
	skipToBrotherPage : function(title){
		var array = $(".child-item",parent.document);
		$(array).hide();
		$(array).each(function(i){
			if($(this).attr("title")==title){
				var url = $(this).attr("name");
				$(this).addClass("active-child-item");
				$(this).show();
				$(this).siblings().show();
				$(this).parent().children().first().children().first().removeClass("contraction").addClass("expand");
				$("#content-frame",parent.document).attr("src",url);
			}else{
				$(this).removeClass("active-child-item");
				$(this).parent().children().first().children().first().removeClass("expand").addClass("contraction");
			}
		});
	},
	skipToAnyPage : function(title,num){
		var array = $(".child-item",parent.document);
		
		$(".menu-item",parent.document).removeClass("cur-active");	// 隐藏一级菜单
		$(".nav-child-menu-box",parent.document).hide();			// 隐藏二级菜单
		$(array).hide();											// 隐藏三级菜单
		$(".child em",parent.document).removeClass("expand").addClass("contraction"); //收起三级菜单下拉框
		var firstMenu;
		
		$(array).each(function(i){
			if($(this).attr("title")==title){
				
				var url = $(this).attr("name");
				firstMenu = $(this).parent().parent().attr("father_name");
				parent.displayMenu = firstMenu;
				if(num==null || num=='undefined'){
					$(this).parent().children().first().children().first().removeClass("contraction").addClass("expand");
					$(this).addClass("active-child-item");
					$(this).show();
					$(this).siblings().show();
					$(this).parent().parent().show();
					$(".menu-item[title='"+firstMenu+"']",parent.document).addClass("cur-active");
					$("#content-frame",parent.document).attr("src",url);
				}else if(num==1 && firstMenu=='我的采购'){
					$(this).parent().children().first().children().first().removeClass("contraction").addClass("expand");
					$(this).addClass("active-child-item");
					$(this).show();
					$(this).siblings().show();
					$(this).parent().parent().show();
					$(".menu-item[title='"+firstMenu+"']",parent.document).addClass("cur-active");
					$("#content-frame",parent.document).attr("src",url);
				}else if(num==2 && firstMenu=='我的销售'){
					$(this).parent().children().first().children().first().removeClass("contraction").addClass("expand");
					$(this).addClass("active-child-item");
					$(this).show();
					$(this).siblings().show();
					$(this).parent().parent().show();
					$(".menu-item[title='"+firstMenu+"']",parent.document).addClass("cur-active");
					$("#content-frame",parent.document).attr("src",url);
				}
			}
		});
		
	},
	getMessageConfig : function(roleDesc,insertId){
		
		switch (roleDesc){ 
			case "采购员" :
				$("#"+insertId).prepend(util.getMessageLi("采购商订单消息","订单消息",300));
				$("#"+insertId).prepend(util.getMessageLi("采购商设置竞标消息","竞标消息",100));
				break;
			case "采购经理" : 
				$("#"+insertId).prepend(util.getMessageLi("采购商审核通知消息","审核消息",500));
				$("#"+insertId).prepend(util.getMessageLi("采购商订单消息","订单消息",300));
				$("#"+insertId).prepend(util.getMessageLi("采购商设置竞标消息","竞标消息",100));
				break;
			case "销售员" : 
				$("#"+insertId).prepend(util.getMessageLi("供应商订单消息","订单消息",400));
				$("#"+insertId).prepend(util.getMessageLi("供应商设置投标消息","投标消息",200));
				break;
			case "销售经理" :
				$("#"+insertId).prepend(util.getMessageLi("供应商订单消息","订单消息",400));
				$("#"+insertId).prepend(util.getMessageLi("供应商设置投标消息","投标消息",200));
				break;
			case "采购决策人" : 
				$("#"+insertId).prepend(util.getMessageLi("采购商审核通知消息","审核消息",500));
				$("#"+insertId).prepend(util.getMessageLi("采购商订单消息","订单消息",300));
				$("#"+insertId).prepend(util.getMessageLi("采购商设置竞标消息","竞标消息",100));
				break;
			case "销售决策人" : 
				$("#"+insertId).prepend(util.getMessageLi("供应商订单消息","订单消息",400));
				$("#"+insertId).prepend(util.getMessageLi("供应商设置投标消息","投标消息",200));
				break;
			case "采购决策人＋销售决策人" : 
				$("#"+insertId).prepend(util.getMessageLi("采购商审核通知消息","采购商审核消息",500));
				$("#"+insertId).prepend(util.getMessageLi("采购商订单消息","采购商订单消息",300));
				$("#"+insertId).prepend(util.getMessageLi("采购商设置竞标消息","采购商竞标消息",100));
				$("#"+insertId).prepend(util.getMessageLi("供应商订单消息","供应商订单消息",400));
				$("#"+insertId).prepend(util.getMessageLi("供应商设置投标消息","供应商投标消息",200));
				break;
			default : alert("没找到角色");
		}
		
		
	},
	getMessageLi : function(title,msg,type){
		var liStr = '<li class="item-li content-line-height" title="'+title+'"><div class="percent-box percent-20">'+msg+'</div>'+
	        		'<div class="percent-box percent-30"></div><div class="percent-box percent-20" style="float: right">'+ 
	        		'<em class="toggle-diy toggle-active" type="'+type+'"></em></div></li>';
		return liStr;
	}
};